<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('上市项目列表') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input
          v-model="queryParams.dealName"
          :placeholder="$t('项目名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('市场')" prop="market">
        <el-select v-model="queryParams.market" :placeholder="$t('市场')" clearable>
          <el-option
            v-for="dict in marketOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('证券代码')" prop="stockCode">
        <el-input
          v-model="queryParams.stockCode"
          :placeholder="$t('证券代码')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['listed:base:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="listedDealList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" min-width="160">
        <template slot-scope="scope">
          <el-link type="primary" class="link_a" @click="openTabs(scope.row)">{{ scope.row.dealName }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('市场')" align="center" prop="market" :formatter="marketFormat" min-width="100" />
      <el-table-column :label="$t('证券代码')" align="center" prop="stockCode" min-width="120" />
      <el-table-column :label="$t('上市日期')" align="center" prop="launchDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.launchDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('总股本(万股)')" align="center" prop="totalEquity" width="120">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.totalEquity) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('最新收盘价(元/股)')" align="center" prop="closePrice" width="140">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.closePrice) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('市值') + $t('金额单位')" align="center" prop="marketValue" width="120">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.marketValue, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('负责人')" align="center" prop="personChargeName" min-width="120" />
      <el-table-column :label="$t('是否存在董监高')" align="center" prop="whetherBod" :formatter="whetherBodFormat" min-width="120" />
      <el-table-column :label="$t('我方持有股数(万股)')" align="center" prop="shareHold" min-width="140">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.shareHold) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('持股比例(%)')" align="center" prop="shareRate" min-width="120">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.shareRate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('我方投资总金额') + $t('金额单位')" align="center" prop="totalInvestAmount" min-width="150">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalInvestAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否解禁')" align="center" prop="releaseState" min-width="120" />
      <el-table-column :label="$t('最新解禁日期')" align="center" prop="latestReleaseDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.latestReleaseDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('总流通股(万股)')" align="center" prop="totalCirculatingShares" min-width="140">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalCirculatingShares) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('总禁售股数(万股)')" align="center" prop="totalBanShares" min-width="140">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalBanShares) }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['listed:base:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}
          </el-button>
          <el-button
            v-hasPermi="['listed:base:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改上市项目管理对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <listedDealForm ref="listedDealForm" />
    </el-dialog>
    <!-- 上市项目详情 -->
    <!--    <el-dialog :title="$t(title)" :visible.sync="tabFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogFormPcwMedical" append-to-body>
      <listedDealTabs ref="listedDealTabs" :listed-id="listedId" :deal-id="dealId" />
    </el-dialog>-->
    <!-- 上市项目详情 -->
    <el-dialog :title="$t(title)" :visible.sync="tabFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogFormPcwMedical" append-to-body>
      <listedDealInfo ref="listedDealInfo" :listed-id="listedId" :deal-id="dealId" />
    </el-dialog>
  </div>
</template>

<script>
import { listListedDeal, delListedDeal } from '@/api/deal/listed/base/listedDeal'
import listedDealForm from './listedDealForm.vue'
import listedDealInfo from './listedDealInfo.vue'

export default {
  components: {
    listedDealForm,
    listedDealInfo
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 上市项目管理表格数据
      listedDealList: [],
      // 弹出层标题
      title: '上市项目管理',
      // 是否显示弹出层
      formOpen: false,
      // 上市项目tab
      tabFormOpen: false,
      // 市场(沪市、深市、港股)字典
      marketOptions: [],
      // 是否字典
      yesNoOptions: [],
      // 查询参数
      queryParams: {
        dealName: undefined,
        market: undefined,
        stockCode: undefined,
        personCharge: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 上市项目ID
      listedId: '',
      // 项目ID
      dealId: '',
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getDicts('listed_market').then(response => {
      this.marketOptions = response.data
    })
    this.getDicts('sys_yes_no').then(response => {
      this.yesNoOptions = response.data
    })
    this.getList()
  },
  methods: {
    /** 查询上市项目管理列表 */
    getList() {
      this.loading = true
      this.queryParams.dealType = (this.$route.query.dealType === undefined ? 'equity' : this.$route.query.dealType)
      listListedDeal(this.queryParams).then(response => {
        this.listedDealList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 市场(沪市、深市、港股)字典翻译
    marketFormat(row) {
      return this.selectDictLabel(this.marketOptions, row.market)
    },
    // 是否字典翻译
    whetherBodFormat(row) {
      return this.selectDictLabel(this.yesNoOptions, row.whetherBod)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: undefined,
        dealName: undefined,
        market: undefined,
        stockCode: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.listedDealForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.listedDealForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delListedDeal(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    // 打开上市项目的tab页
    openTabs(row) {
      this.tabFormOpen = true
      this.title = '上市项目'
      this.listedId = row.id
      this.dealId = row.dealId
      this.$nextTick(() => {
        this.$refs.listedDealInfo.listLoad()
      })
    }
  }
}
</script>
